<?php
namespace Home\Controller;
use Think\Controller;
class UploadController extends Controller {
	public function index(){
		$this->display();
	}
	
	public function upload(){
		$upload = new \Think\Upload();// 实例化上传类
	    $upload->maxSize   =     3145728 ;// 设置附件上传大小
	    $upload->exts      =     array('xls', 'jpg', 'gif', 'png', 'jpeg' ,'txt', 'php', 'doc', 'xlsx','css');// 设置附件上传类型
	    $upload->rootPath  =     'Public/upload/'; // 设置附件上传根目录
	    $upload->savePath  =     ''; // 设置附件上传（子）目录
	    $upload->autoSub  =     false; // 设置附件上传（子）目录
	    $upload->saveName = '';
	    // 上传文件 
	    $info   =   $upload->upload();
	    if(!$info) {// 上传错误提示错误信息
	        $this->error($upload->getError());
	    }else{// 上传成功
	    	$data['drive_url'] = $info['file']['savename'];
	    	$data['drive_name'] = $_POST['drive_name'];
	    	$res = D('drive')->insertDriveInfo($data);
	    	if(!$res){
	    		$this->error($res->getError());
	    	}else{
	    		 $this->success('上传成功！');
	    	}
	    }
	}
}
	
?>